package com.cskaoyan.jdbc.crud;

import com.mysql.jdbc.Driver;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.sql.Statement;

/**
 * 创建日期: 2022/11/16 16:04
 *
 * @author ciggar
 */
public class DeleteDemo {

    public static void main(String[] args) throws SQLException {

        // 1. 注册驱动
        DriverManager.registerDriver(new Driver());

        // 2. 获取连接
        Connection connection = DriverManager.getConnection("jdbc:mysql://localhost:3306/46th?useSSL=false&characterEncoding=utf8",
                "root",
                "123456");

        // 3. 获取statement对象
        Statement statement = connection.createStatement();

        // 4. 发送SQL语句
        int affectedRows = statement.executeUpdate("delete from stu where id in (2001,2002)");

        // 5. 解析结果集
        System.out.println("affectedRows:" + affectedRows);

        // 6. 关闭连接
        statement.close();
        connection.close();

    }
}
